import java.util.ArrayList;
import java.util.List;

public class LetterCasePermutation {

    List<String> ans = new ArrayList<>();
    public List<String> letterCasePermutation(String s) {
        StringBuilder stringBuilder = new StringBuilder(s);
        process(stringBuilder, 0);
        return ans;
    }

    public void process(StringBuilder stringBuilder, int i) {
        if (i == stringBuilder.length()) {
            ans.add(new String(stringBuilder.toString()));
            return;
        }

        char c= stringBuilder.charAt(i);
        if (isNum(c)) {
            process(stringBuilder, i + 1);
            return;
        } else {
            if (c >= 65 && c <= 90) {
               stringBuilder.replace(i, i + 1, new String((char)(c + 32) + ""));
               process(stringBuilder, i + 1);
               stringBuilder.replace(i, i + 1, c + "");
               process(stringBuilder, i + 1);
            } else {
                stringBuilder.replace(i, i + 1, new String((char)(c - 32) + ""));
                process(stringBuilder, i + 1);
                stringBuilder.replace(i, i + 1, c + "");
                process(stringBuilder, i + 1);
            }
        }
    }

    public boolean isNum(char c) {
        if (c >= 48 && c <= 57) return true;
        return false;
    }
}
